//
//  VideoDetialView.m
//  KeleAppProject
//
//  Created by 周岑 on 2018/1/21.
//  Copyright © 2018年 Cen Zhou. All rights reserved.
//

#import "VideoDetialView.h"
#import "TagView.h"
#import "LogoNumberView.h"
@interface VideoDetialView()
@property (nonatomic, strong) YYTextLayout *layout;
@property (nonatomic, strong) UIButton *attentBtn;
@end
@implementation VideoDetialView

- (instancetype)init{
    
    if (self = [super init ]) {
        [self loadSubviewsOnVideoDetialView];
    }
    return self;
    
    
}

- (void)loadSubviewsOnVideoDetialView{
    
    UIView *topSectionView = [[UIView alloc]init];
    topSectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:topSectionView];
    [topSectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(136*HEIGHT);
    }];
    
    // title
    YYLabel *textLabel = [YYLabel new];
    textLabel.text = @"视频标题内容视频标题内容视频标题内容视频标题内容视频标题内容";
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc]initWithString:textLabel.text];
    text.yy_color = KLColor_B6;
    text.yy_font = [UIFont fontWithName:@"PingFangSC-Medium" size:17*WIDTH];
    CGSize size = CGSizeMake(KLScreenW - 30*WIDTH, CGFLOAT_MAX);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:text];
    textLabel.textLayout = layout;
    self.layout = layout;
    [topSectionView addSubview:textLabel];
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topSectionView).offset(10*HEIGHT);
        make.left.equalTo(topSectionView).offset(15*WIDTH);
        make.right.equalTo(topSectionView).offset(-15*WIDTH);
        make.height.mas_equalTo(layout.textBoundingSize.height);
    }];
    
    
    // 标签
    // 标签的界面
    TagView *tagView = [[TagView alloc]init];
    [topSectionView addSubview:tagView];
    [tagView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(textLabel.mas_bottom);
        make.left.right.equalTo(topSectionView);
        make.height.mas_equalTo(48*HEIGHT);
    }];
    [tagView addTagViewWithDataArray:@[@"哈哈哈",@"哈哈哈",@"lalal"]];
    
    // 观看次数
    UILabel *lookNum = [[UILabel alloc]init];
    lookNum.text = @"5625次观看";
    lookNum.textColor = KLColor_B5;
    lookNum.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12*WIDTH];
    [topSectionView addSubview:lookNum];
    [lookNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tagView.mas_bottom);
        make.left.equalTo(topSectionView).offset(15*WIDTH);
    }];
    
    //
    LogoNumberView *downLoadView = [[LogoNumberView alloc]init];
    [topSectionView addSubview:downLoadView];
    downLoadView.signalDelegate = [RACSubject subject];
    [downLoadView.signalDelegate subscribeNext:^(id x) {
        if (self.downDelegate) {
            [self.downDelegate sendNext:nil];
        }
    }];
    
    [downLoadView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lookNum);
        make.left.equalTo(topSectionView).offset(233*WIDTH);
        make.width.mas_equalTo(50*WIDTH);
        make.height.mas_equalTo(20*HEIGHT);
    }];
    [downLoadView setOriginValuesWithDataDic:@{@"imageStr":@"icon_xiazai",@"title":@"下载"}];
    
    LogoNumberView *praseNum = [[LogoNumberView alloc]init];
    [topSectionView addSubview:praseNum];
    [praseNum mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(downLoadView);
        make.left.equalTo(downLoadView.mas_right).offset(30*WIDTH);
        make.width.mas_equalTo(50*WIDTH);
        make.height.mas_equalTo(20*HEIGHT);
    }];
    
    [praseNum setValuesWithDataDic:@{@"imageStr":@"home_icon_dianzan",@"title":@"756"}];
    
    // 分割线
    UIView *firstLineView = [[UIView alloc]init];
    firstLineView.backgroundColor = KLColor_B3;
    [topSectionView addSubview:firstLineView];
    [firstLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(topSectionView);
        make.height.mas_equalTo(1);
    }];
    
    // 作者
    UIView *authorView = [[UIView alloc]init];
    authorView.backgroundColor = [UIColor whiteColor];
    [self addSubview:authorView];
    [authorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topSectionView.mas_bottom);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(66*HEIGHT);
    }];
    
    UIImageView *profileImageView = [[UIImageView alloc]init];
    profileImageView.image = [UIImage imageNamed:@"info_touxiang"];
    profileImageView.layer.masksToBounds = YES;
    profileImageView.layer.cornerRadius = 16*WIDTH;
    [authorView addSubview:profileImageView];
    [profileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(32*WIDTH);
        make.top.equalTo(authorView).offset(15*HEIGHT);
        make.left.equalTo(authorView).offset(15*WIDTH);
    }];
    
    UILabel *nameLb = [[UILabel alloc]init];
    nameLb.text = @"罗珊珊";
    nameLb.textColor = KLColor_B6;
    nameLb.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14*WIDTH];
    [authorView addSubview:nameLb];
    [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(authorView).offset(15*HEIGHT);
        make.left.equalTo(profileImageView.mas_right).offset(12*WIDTH);
    }];
    
    UILabel *timeLb = [[UILabel alloc]init];
    timeLb.text = @"2017-10-08 20:16";
    timeLb.textColor = KLColor_B7;
    timeLb.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13*WIDTH];
    [authorView addSubview:timeLb];
    [timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLb.mas_bottom);
        make.left.equalTo(nameLb);
    }];
    
    
    UILabel *phoneType = [[UILabel alloc]init];
    phoneType.text = @"iphone6";
    phoneType.textColor = KLColor_B7;
    phoneType.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13*WIDTH];
    [authorView addSubview:phoneType];
    [phoneType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(timeLb);
        make.left.equalTo(timeLb.mas_right).offset(4.5*WIDTH);
    }];
    
    UIButton *attentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [attentButton setImage:[UIImage imageNamed:@"info_guanzhu_icon_jiahao"] forState:UIControlStateNormal];
    attentButton.backgroundColor = KLColor_A1;
    attentButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13*WIDTH];
    [attentButton setTitle:@"关注" forState:UIControlStateNormal];
    [attentButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [attentButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 10*WIDTH)];
    [[attentButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        
    }];
    self.attentBtn = attentButton;
    [authorView addSubview:attentButton];
    [attentButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(authorView);
        make.right.equalTo(authorView).offset(-15*WIDTH);
        make.width.mas_equalTo(66*WIDTH);
        make.height.mas_equalTo(28*HEIGHT);
    }];
    
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = KLColor_B3;
    [authorView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(authorView);
        make.height.mas_equalTo(1);
    }];
}

- (void)layoutSublayersOfLayer:(CALayer *)layer{
    [super layoutSublayersOfLayer:layer];
   
    [self.attentBtn layoutIfNeeded];
    [self.attentBtn setRadiusWithValue:14*HEIGHT];
}


@end
